<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<%@	taglib prefix="c"			uri="http://java.sun.com/jsp/jstl/core"%>
<%@	taglib prefix="fmt"		uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@	taglib prefix="fn"		uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="spring"	uri="http://www.springframework.org/tags" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<title>중고마트</title>
</head>
<body>
<%
	boolean isValid = true;
	String message = "";
	
	String dealCode = (String)request.getAttribute("dealCode");
	if ( "invalid".equals(dealCode) ) {
		isValid = false;
		message = "본인이 등록한 상품을 관심 상품으로 등록할 수 없습니다.";
	} else if ( "duplicated".equals(dealCode) ) {
		isValid = false;
		message = "같은 조건으로 등록한 관심 상품이 이미 존재 합니다.";
	} else if ( "noMatchedProduct".equals(dealCode) ) {
		message = "조건에 해당하는 상품이 없습니다. 이후 조건에 해당하는 상품이 등록되면 알람을 받으실 수 있습니다.";
		isValid = false;
	}
%>
<section id="deal" data-role="page">
    <header data-role="header">
    	<a href="index.do" data-role="button" data-icon="home" data-iconpos="notext" data-inline="true">Home</a>
    	<a data-role="button" href="logout.do" class="ui-btn-right" data-ajax="false">로그아웃</a>
    	<h1 style="text-overflow:clip;margin-left:10%;margin-right:10%">거래요청완료</h1>
    </header>
    
    <c:choose>
    	<c:when test="<%= isValid==false %>">
    		<h3 style="text-align: center"><%= message %></h3>
    	</c:when>
    	<c:otherwise>
    	<c:forEach var="product" items="${ matchedProducts }">
	    	<div data-role="content">
		    	<div class="productImage">
    				<img alt="상품이미지" src="${ product.image_path }" width="100%" height="100%" style="margin: 0pt auto; display: table-cell; text-align: center; vertical-align: middle;">
    			</div>
		        <p align="center">'${ product.title }' 상품(가격:${ product.price }원)에 대해 거래 요청을 완료 했습니다.</p><br>
		        <hr/>
		    </div>	
		</c:forEach>
    	</c:otherwise>
    </c:choose>
    
    <footer data-role="footer" data-position="fixed">
    	<div data-role="navbar" data-iconpos="left">
			<ul>
				<li><a id="products" href="products.do" data-icon="grid" rel="external">전체 상품</a></li>
				<li><a id="myProducts" href="myProducts.do" data-icon="bars" rel="external">내 상품</a></li>
				<li><a id="myFavorites" href="myFavorites.do" data-icon="star" rel="external">내 관심상품</a></li>
			</ul>
		</div><!-- /navbar -->
    </footer>
</section>
</body>
<style>
hr { border-top:1px solid #9C9C9C; border-bottom:1px solid #F6F6F6; }
p { margin-bottom: 0px; }
.productImage { border:2px solid silver; height:200px; }
</style>
<script>
$(document).bind('pageinit', function() {
	
	var fromPage = "${ fromPage }";
	if ( fromPage == "favorite" ) {
		$('#myFavorites').addClass("ui-btn-active");
	} else {
		$('#products').addClass("ui-btn-active");
	}
	
});
</script>
</html>